//
//  Simple message queuing broker
//  Same as request-reply broker but using QUEUE device
//

package main

import (
	"fmt"
	"os"
	"zmq"
)

func zmq_main() os.Error {
	context, err := zmq.Init(1)
	if err != nil {
		return err
	}
	defer context.Close()

	frontend, err := context.Socket(zmq.ROUTER)
	if err != nil {
		return err
	}
	defer frontend.Close()

	err = frontend.Bind("tcp://*:5559")
	if err != nil {
		return err
	}

	backend, err := context.Socket(zmq.DEALER)
	if err != nil {
		return err
	}
	defer backend.Close()

	err = backend.Bind("tcp://*:5560")
	if err != nil {
		return err
	}

	err = zmq.Device(zmq.QUEUE, frontend, backend)
	if err != nil {
		return err
	}
	return nil
}

func main() {
	fmt.Println("Simple message queuing broker")
	err := zmq_main()
	if err != nil {
		fmt.Println(err)
	}
}
